﻿using Microsoft.EntityFrameworkCore.ChangeTracking;
using System.Text.Json;
using XiaTiNode.Core.Type;

namespace FaceService.Infrastructure.Config;
class FaceConfig : IEntityTypeConfiguration<Face>
{
    public void Configure(EntityTypeBuilder<Face> builder)
    {
        builder.ToTable("T_Faces");
        builder.HasQueryFilter(f => f.Status != StatusType.Deleted);
        builder.Property(f => f.Name).IsUnicode().HasMaxLength(50);
        builder.Property(f => f.StudentId).IsUnicode(false).HasMaxLength(50);
        builder.Property(f => f.Image).IsUnicode(false).HasMaxLength(200);
        builder.Property(f => f.FaceExtract).HasConversion(
            v => JsonSerializer.Serialize(v, (JsonSerializerOptions)null!),
            v => JsonSerializer.Deserialize<List<float>>(v, (JsonSerializerOptions)null!)!,
            new ValueComparer<List<float>>(
                (c1, c2) => c1!.SequenceEqual(c2!),
                c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
                c => c.ToList())).HasColumnType("json");
    }
}